import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';

class JudgeMain extends StatefulWidget {
  @override
  _JudgeMainState createState() => _JudgeMainState();
}

class _JudgeMainState extends State<JudgeMain> {
  int _currentIndex;

  int _checkboxSelected = -1;

  //获取所有的数据
  @override
  void initState() {
    // TODO: implement initState
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text("判断题"),
      ),
      body: ConstrainedBox(
        constraints: BoxConstraints.expand(),
        child: Stack(
          alignment: Alignment.topCenter,
          children: [
            Column(
              children: getContentData(),
            ),
            Positioned(
              child: Padding(
                padding: EdgeInsets.all(16),
                child: Row(
                  mainAxisAlignment: MainAxisAlignment.spaceAround,
                  children: [
                    RaisedButton(
                      onPressed: () {},
                      child: Text(
                        "last",
                        style: TextStyle(fontSize: 36),
                      ),
                    ),
                    RaisedButton(
                      onPressed: () {},
                      child: Text(
                        "last",
                        style: TextStyle(fontSize: 36),
                      ),
                    ),
                    RaisedButton(
                      onPressed: () {},
                      child: Text(
                        "last",
                        style: TextStyle(fontSize: 36),
                      ),
                    ),
                    RaisedButton(
                      onPressed: _onTabNext,
                      child: Text(
                        "next",
                        style: TextStyle(fontSize: 36),
                      ),
                    ),
                  ],
                ),
              ),
              left: 0,
              right: 0,
              bottom: 0,
            )
          ],
        ),
      ),
    );
  }

  //返回正文内容
  List<Widget> getContentData() {
    var list = <Widget>[];
    //总记录
    list.add(Text(
      "50/100",
      style: TextStyle(fontSize: 18),
    ));
    list.add(
      Divider(color: Colors.green),
    );
    list.add(
      Text(
          "topitopictopictopictopictopictopictopictopictopictopictopictopictopictopictopictopictopictopictopictopictopictopictopictopictopictopictopictopictopictopictopictopictopictopictopictopictopictopictopictopictopictopictopictopicc"),
    );
    list.add(
      Divider(color: Colors.green),
    );

    getItemAnswer(list);

    return list;
  }

  void getItemAnswer(List<Widget> list) {
    list.add(Row(
      mainAxisAlignment: MainAxisAlignment.center,
      children: [
        //内容
        Checkbox(
          value: _checkboxSelected == 0,
          activeColor: Colors.red, //选中时的颜色
          onChanged: (value) {
            setState(() {
              _checkboxSelected = 0;
            });
          },
        ),
        Text("failed"),
        SizedBox(
          width: 100,
        ),
        Checkbox(
          value: _checkboxSelected == 1,
          activeColor: Colors.red, //选中时的颜色
          onChanged: (value) {
            setState(() {
              _checkboxSelected = 1;
            });
          },
        ),
        Text("right"),
      ],
    ));
  }

  void _onTabNext() {
    print("_checkboxSelected = $_checkboxSelected");
  }
}
